package com.kunbo.cn.service.impl.core.otherbusiness;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.kunbo.cn.dao.core.otherbusiness.OtherWarehousingNoticeDao;
import com.kunbo.cn.entity.core.otherbusiness.OtherWarehousingNotice;
import com.kunbo.cn.service.core.otherbusiness.OtherWarehousingNoticeService;
import com.kunbo.cn.util.date.SDate;
import com.kunbo.cn.util.retu.Pages;
@Service
public class OtherWarehousingNoticeServiceImpl implements OtherWarehousingNoticeService{
	@Autowired
	private OtherWarehousingNoticeDao dao;
	@Autowired
	private JdbcTemplate jdbc;
	@Override
	public void save(OtherWarehousingNotice notice) {
		notice.setMake_time(SDate.getSystemDateToString());
		dao.save(notice);
	}
	@Override
	public void update(OtherWarehousingNotice notice) {
		notice.setMake_time(SDate.getSystemDateToString());
		dao.save(notice);
	}

	@Override
	public int updateState(Integer id, String audit_status) {
		String sql = "UPDATE \r\n" +
		        "business_other_warehousing_notice_manage  \r\n"+
		        " set audit_status='"+audit_status+"'\r\n "+
		        " WHERE  id="+id+"";
				 int i=jdbc.update(sql);
				return i;
	}

	@Override
	public void delete(Integer id) {
		dao.delete(id);
	}

	@Override
	public OtherWarehousingNotice findById(Integer id) {
		return dao.findOne(id);
	}

	@Override
	public Pages list(String startTime,String endTime,String supplier,String receiving_unit,String warehouse,String materiel,String mater_type,String car_number,Integer page,Integer pageSize) {
			String sql1 = "select * from business_other_warehousing_notice_manage where 1=1 ";
	if (startTime != null && !startTime.equals("")) {
		sql1 += " and make_time >='" + startTime +"'" ;
	}
	if (endTime != null && !endTime.equals("")) {
		sql1 += " and make_time <='" + endTime +"'" ;
	}
	if (materiel != null && !materiel.equals("")) {
		sql1 += " and materiel like'" + materiel +"'" ;
	}//mater_type//car_number
	if (mater_type != null && !mater_type.equals("")) {
		sql1 += " and mater_type like'" + mater_type +"'" ;
	}
	if (car_number != null && !car_number.equals("")) {
		sql1 += " and car_number like'" + car_number +"'" ;
	}
	if (supplier != null && !supplier.equals("")) {
		sql1 += " and supplier like'" + supplier +"'" ;
	}if (receiving_unit != null && !receiving_unit.equals("")) {
		sql1 += " and receiving_unit  like'" + receiving_unit +"'" ;
	}if (warehouse != null && !warehouse.equals("")) {
		sql1 += " and warehouse ='" + warehouse +"'" ;
}
	String sql2="";
	sql2+= " order by id  desc  limit " + (page * pageSize) +"," + pageSize;
	System.out.println(sql1+"<!!!!!!!!!!!!!!!!!!!!");
	  String sql=sql1.concat(sql2);//获取数据sql
	List<Map<String, Object>> list = jdbc.queryForList(sql);
	
	for (Map<String, Object> map : list) {
		String reminder_status_sql = "select id,text from select_waybill_order where id = "+String.valueOf(map.get("reminder_status").toString())  +"";
		if(jdbc.queryForList(reminder_status_sql) != null && jdbc.queryForList(reminder_status_sql).size() > 0) {
			map.put("reminder_status", jdbc.queryForList(reminder_status_sql).get(0).get("text"));
		}
	}
	
	Pages pages =new Pages();
	  Integer count = jdbc.queryForList(sql1).size();
	  pages.setTotal(count);
	  pages.setData(list);
	return pages;
}
	@Override
	public List<Map<String, Object>> getSuppliers() {
		String sql = "select id,name from business_supplier_manage";
		return jdbc.queryForList(sql);
	}//
	@Override
	public List<Map<String, Object>> getCarInfo(String id) {
		String sql = "select * from business_other_warehousing_notice_manage where '"+id+ "'";
		return jdbc.queryForList(sql);
	}
	@Override
	public List<Map<String, Object>> matterid() {
		String sql = "select id,name from business_matter_type_manage";
		return jdbc.queryForList(sql);
	}

	@Override
	public List<Map<String, Object>> getMatter(String mater_type) {
		String sql = "select id,name from business_materials_manage where mater_type='"+mater_type+"' ";
		return jdbc.queryForList(sql);
	}
	@Override
	public List<Map<String, Object>>getOrganizations(){
		String sql = "select id,title from business_organization_manage";
		return jdbc.queryForList(sql);
	}

	@Override
	public List<Map<String, Object>> carDriver() {
		// TODO Auto-generated method stub
		String sql = "select id , name ,idcrad from driver_management where 1=1";
		return jdbc.queryForList(sql);
	}
	@Override
	public List<Map<String, Object>> carNumber() {
		String sql = "select id,license_plate_number  from  vehicle_management where 1=1 ";
		return jdbc.queryForList(sql);
	}//
	@Override
	public List<Map<String, Object>> depot() {
		String sql = "select id,name from business_depot_manage where 1=1 ";
		return jdbc.queryForList(sql);
	}//Depo   reminderStatus
	@Override
	public List<Map<String, Object>> reminderStatus() {
		String sql = "select id,text from select_waybill_order where 1=1 ";
		return jdbc.queryForList(sql);
	}
	
}
	

